Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize "constant_string".Length #2099

Closed

Conversation

monojenkins
Copy link
Contributor

!! This PR is a copy of mono/mono#16898, please do not edit or review it in this repo !!
!! Merge the PR only after the original PR is merged !!



```csharp
static int Test() => "Hello".Length; // replace with just 5

Before:
```asm
movabs rax,0x7fd6c1758160
mov    eax,DWORD PTR [rax]
ret 

Now:

mov    eax,0x5
ret

Also, handles cases after inlining, e.g.:

bool Validate(string str)
{
    return str.Length > 0 && str.Length <= 100;
}

bool Test()
{
    return Validate("Hello");  // Validate() will be inlined
}

New codegen for Test:

mov    eax, 1     ; return true
ret  

I have a similar PR for CoreCLR: #1378
jit-diff report found >30k bytes of improvements.

```csharp
static int Test() => "Hello".Length; // replace with just `5`
```
Before:
```asm
movabs rax,0x7fd6c1758160
mov    eax,DWORD PTR [rax]
ret
```
Now:
```asm
mov    eax,0x5
ret
```

Also, handles cases after inlining, e.g.:
```csharp
bool Validate(string str)
{
    return str.Length > 0 && str.Length <= 100;
}

bool Test()
{
    return Validate("Hello");  // Validate() will be inlined
}
```
New codegen for `Test`:
```asm
mov    eax, 1     ; return true
ret
```

I have a similar PR for CoreCLR: dotnet#1378
jit-diff report found >30k bytes of improvements.
@stephentoub
Copy link
Member

@EgorBo, @akoeplinger, what's the best way to make forward progress on some of these mirrored mono PRs that haven't been touched in a while? e.g. in this case the Mono PR hasn't been updated in a month and a half. Thanks.

@EgorBo
Copy link
Member

EgorBo commented Feb 20, 2020

let me close it, it was just a draft in mono/mono

@EgorBo EgorBo closed this Feb 20, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants